package ar.edu.uba.fi.jmit.integrationtest.objectcount;

import ar.edu.uba.fi.jmit.integrationtest.IntegrationTest;

public class ObjectCountTest extends IntegrationTest {
	
	private Thread objectConstructorThread;

	@Override
	protected void runTest() {
		logger.info("runTest");
		build20Objects();
		lounchObjectCounstructor();
	}

	private void lounchObjectCounstructor() {
		logger.info("lounchObjectCounstructor");
		objectConstructorThread = new Thread() {
			public void run() {
				while(!stopping) {
					new TestObjectEverySecond();
					try {
						Thread.sleep(1000);
					} catch (InterruptedException e) {
						logger.error(e);
					}
				}
			};
		};
		objectConstructorThread.start();
	}

	private void build20Objects() {
		logger.info("build20Objects");
		
		for(int i = 0; i < 20; i++) {
			new TestObject();
		}
		
	}

	@Override
	protected boolean allThreadsStopped() {
		if(objectConstructorThread != null && objectConstructorThread.isAlive()) {
			return false;
		}
		return true;
	}

}
